package com.itheima;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AnnotationAdvice {

    // 前置通知
    @Before("execution(* com.itheima.dao.UserMapper.*(..))")
    public void beforeAdvice() {
        System.out.println("这是基于注解的前置通知!");
    }

    // 环绕通知
    @Around("execution(* com.itheima.dao.UserMapper.*(..))")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("这是基于注解的环绕通知之前的部分!");
        Object result = joinPoint.proceed();
        System.out.println("这是基于注解的环绕通知之后的部分!");
        return result;
    }

    // 返回通知
    @AfterReturning("execution(* com.itheima.dao.UserMapper.*(..))")
    public void afterReturningAdvice() {
        System.out.println("这是基于注解的返回通知(方法不出现异常时调用)!");
    }
}

